package com.itheima.springbootinit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Value("${name}")
    private String name;

    @Value("${person.name}")
    private String name2;

    @Value("${person.age}")
    private int age;

    @Value("${location[0]}")
    private String location1;
    @Value("${location[1]}")
    private String location2;

    @Value("${msg1}")
    private String msg1;
    @Value("${msg2}")
    private String msg2;

    @Autowired
    private Environment env;

    @Autowired
    private Person person;


    @RequestMapping("/hello3")
    @ResponseBody
    public String test3(){
        System.out.println(person);
        return "success";
    }


    @RequestMapping("/hello2")
    @ResponseBody
    public String test2(){
        System.out.println(name);
        System.out.println(name2);
        System.out.println(age);
        System.out.println(location1);
        System.out.println(location2);
        System.out.println(msg1);
        System.out.println(msg2);
        System.out.println(env.getProperty("person.name"));
        System.out.println(env.getProperty("location[0]"));
        return "success";
    }


    @RequestMapping("/hello")
    @ResponseBody
    public String test1(){
        return "success";
    }
}
